home *** CD-ROM | disk | FTP | other *** search
- Path: news.rmii.com!usenet
- From: bmeardon@rmii.com (Brandon Meardon)
- Newsgroups: comp.lang.c++
- Subject: Re: Help with cin.get()
- Date: Mon, 08 Jan 1996 06:45:10 GMT
- Organization: Rocky Mountain Internet Inc.
- Message-ID: <4cqebj$oje@natasha.rmii.com>
- References: <4cqbja$62n@earth.njcc.com>
- NNTP-Posting-Host: slip858.rmii.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- chris@pluto.njcc.com (Chris Conway) wrote:
-
- >I use this function to input a book title with imbedded blanks:
-
- > void getdata()
- > {
- > cout << "Enter title: ";
- > cin.get(title, LEN);
- > cout << "Enter price: ";
- > cin >> price;
- > }
-
- >problem is, if I execute the function more than once, it skips the title input
- >on the second and every subsequent execution (i.e. the line will resemble:
- > Enter title: Enter price:
- >never offering the oppurtunity to enter the title).
-
- >I suspect this little "bug" arises from a subtle misuse of cin.get(). Can
- >anyone identify it for me? This is obviously a beginner question.
-
- >My thanks and apologies.
- >chris.
- >chris@pluto.njcc.com
-
-
- This is not just a problem with the cin.get method but also when you
- stream the input in useing the >> operator. What I think is happening
- here is that the buffer is not getting properly flushed, you might
- want to look in the reference book to see how you can manualy flush
- the cin buffer.
-
- good luck,
-
- Brandon
-
-
-